package com.ww.springboot.boot.thread.study.base.lock;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * 描述：
 *
 * @author wanwei
 * @since 2021-07-22 17:34
 */
public class LockDemo1 {

    int count = 0;

    private static Thread threadA;
    private static Thread threadB;
    private static Thread threadC;
    private static LockDemo1 lockDemo1 = new LockDemo1();

    private static CountDownLatch countDownLatchB = new CountDownLatch(1);
    private static CountDownLatch countDownLatchC = new CountDownLatch(1);

    public static void main(String[] args) {


        threadA = new Thread(() -> lockDemo1.printA());

        threadB = new Thread(() -> {
            try {
                lockDemo1.printB();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });

        threadC = new Thread(() -> {
            try {
                lockDemo1.printC();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });

        threadC.start();
        threadB.start();
        threadA.start();
    }


    public void printA() {
        System.out.println("A");
        countDownLatchB.countDown();
    }

    public void printB() throws InterruptedException {
        countDownLatchB.await(1000, TimeUnit.MILLISECONDS);
        System.out.println("B");
        countDownLatchC.countDown();
    }

    public void printC() throws InterruptedException {
        countDownLatchC.await(1000, TimeUnit.MILLISECONDS);
        System.out.println("C");
    }

}
